<template>
  <div class="main">
    <item
      v-if="parent.parent"
      :parent='parent.parent'
      @replydata='reply'
    ></item>
    <div class="hear">
      <span>{{parent.account&&parent.account.nickname}}</span>&nbsp;&nbsp;
      <span>{{moment(parent.updated_at).format('YYYY-MM-DD HH:mm:ss')}}</span>
    </div>
    <!-- 中间的嵌套评论 -->
    <!-- 当前的评论 -->
    <div class="s_box">
      <div class="comment">{{parent.content}}</div>
      <span
        class="img"
        v-for="(item,index) in parent.pics"
        :key='index'
      ><img
          :src="baseURL+item.url"
          alt=""
        ></span>
      <div class="reply">
        <a
          href="javascript:;"
          @click="reply((parent.id),(parent.account&&parent.account.nickname))"
        >回复</a>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "@/utils/myaxios";
import moment from "moment";
export default {
  name: "item",
  props: {
    parent: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      baseURL: axios.defaults.baseURL,
    };
  },
  methods: {
    moment,
    reply(id, nickname) {
      this.$emit("replydata", id, nickname);
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  border: 1px solid #ddd;
  background-color: #f9f9f9;
  padding: 3px 3px 3px 3px;

  .hear {
    margin-top: 5px;
    font-size: 12px;
    color: #666666;
    display: flex;
    margin-bottom: 10px;

    span {
      height: 16px;

      img {
        width: 16px;
        height: 16px;
        border-radius: 8px;
      }
    }
  }

  .s_box {
    position: relative;
    &:hover .reply a {
      display: block;
    }

    .comment {
      margin-top: 10px;
    }
    .img {
      display: inline-block;
      width: 80px;
      height: 80px;
      padding: 5px;
      border: 1px dashed #ddd;
      border-radius: 6px;
      margin: 10px 5px 0 25px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .reply {
      height: 14px;
      display: flex;
      justify-content: flex-end;
      a {
        display: none;
        color: #1e50a2;
        font-size: 12px;
      }
    }
  }
}
</style>